home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / libraries / mui20dev.lha / MUI / Developer / Docs / MUIdev.doc < prev    next >
Text File  |  1994-02-11  |  57KB  |  1,407 lines

  1.  
  2.  
  3.                        MUI - MagicUserInterface
  4.  
  5.        A system to create and maintain graphical user interfaces
  6.  
  7.                        Programmer Documentation
  8.  
  9.                 (c) Copyright 1993/94 by Stefan Stuntz
  10.  
  11. Getting Started
  12. ***************
  13.  
  14.    Note: This documentation does not cover all concepts of MUI
  15. programming in detail. It's important that you also read the
  16. accompanying per class autodocs and have a look at the supplied demo
  17. programs!
  18.  
  19. Object Oriented Programming
  20. ===========================
  21.  
  22.    The MUI system is based on BOOPSI, the Basic Object Oriented
  23. Programming System for Intuition. Understanding MUI and understanding
  24. this documentation requires at least a little knowledge about the
  25. concepts of object oriented programming, about classes, objects,
  26. methods and attributes. An absolutely sufficient introduction to these
  27. topics can be found in the "Libraries" part of the "ROM Kernel
  28. Reference Manuals" or in several Amiga mail articles.
  29.  
  30.    When talking about BOOPSI, most people automatically think of BOOPSI
  31. images and BOOPSI gadgets as part of the Amiga operating system.
  32. However, BOOPSI for itself is just a system for object oriented
  33. programming. One could e.g. have object oriented spread sheet software
  34. or object oriented file systems based on BOOPSI, intuition's builtin
  35. classes (gadgetclass, imageclass) are just two from thousands of
  36. possibilities.
  37.  
  38.    The MUI system also uses BOOPSI only as a base for object oriented
  39. programming. Thus, MUI classes are all subclasses of BOOPSI's rootclass
  40. and have nothing in common with the system supplied gadget or image
  41. classes. Unfortunately, Commodore missed some very important topics
  42. when designing these classes, disabling them for use in automatic
  43. layout systems such as MUI. Anyway, MUI features an interface to
  44. BOOPSI's gadgetclass and allows using already available gadgets (e.g.
  45. the Kick 3.x colorwheel) in MUI applications.
  46.  
  47. Available Classes
  48. =================
  49.  
  50.    The MUI system comes with several classes, each of them available as
  51. seperate shared system library. These classes are organized in a tree.
  52. As usual in the OO programming model, objects inherit all methods and
  53. attributes from their true class as well as from all their
  54. superclasses. Here is a quick summary with some short notes what the
  55. classes are used for. More detailed information can be found later in
  56. this document and in the per class autodocs files coming with the
  57. developer archive.
  58.  
  59.      rootclass               (BOOPSI's base class)
  60.      \--Notify               (implements notification mechanism)
  61.         +--Application       (main class for all applications)
  62.         +--Window            (handles intuition window related topics)
  63.         \--Area              (base class for all GUI elements)
  64.            +--Rectangle      (creates empty rectangles)
  65.            +--Image          (creates images)
  66.            +--Text           (creates some text)
  67.            +--String         (creates a string gadget)
  68.            +--Prop           (creates a proportional gadget)
  69.            +--Gauge          (creates a fule gauge)
  70.            +--Scale          (creates a percentage scale)
  71.            +--Boopsi         (interface to BOOPSI gadgets)
  72.            +--Colorfield     (creates a field with changeable color)
  73.            +--List           (creates a line-oriented list)
  74.            !  +--Floattext   (special list with floating text)
  75.            !  +--Volumelist  (special list with volumes)
  76.            !  +--Scrmodelist (special list with screen modes)
  77.            !  \--Dirlist     (special list with files)
  78.            \--Group          (groups other GUI elements - handles layout)
  79.               +--Virtgroup   (handles virtual groups)
  80.               +--Scrollgroup (handles virtual groups with scrollers)
  81.               +--Scrollbar   (creates a scrollbar)
  82.               +--Listview    (creates a listview)
  83.               +--Radio       (creates radio buttons)
  84.               +--Cycle       (creates cycle gadgets)
  85.               +--Slider      (creates slider gadgets)
  86.               +--Coloradjust (creates some RGB sliders)
  87.               \--Palette     (creates a complete palette gadget)
  88.  
  89. Application Theory
  90. ==================
  91.  
  92.    A MUI application consists of a (sometimes very) big object tree
  93. (don't mix up with the class tree explained above).  The root of this
  94. tree is always an instance of application class, called application
  95. object. This application object handles the various communication
  96. channels such as user input through windows, ARexx commands or
  97. commodities messages.
  98.  
  99.    An application object itself would be enough to create non-GUI
  100. programs with just ARexx and commodities capabilities. If you want to
  101. have windows with lots of nice gadgets and other user interface stuff,
  102. you will have to add window objects to your application. Since the
  103. application object is able to to handle any number of children, the
  104. number of windows is not limited.
  105.  
  106.    Window objects are instances of window class and handle all the
  107. actions related with opening, closing, moving, resizing and refreshing
  108. of intuition windows. However, a window for itself is not of much use
  109. without having any contents to display.  That's why window objects
  110. always need a so called root object.
  111.  
  112.    With this root object, we finally reach the gadget related classes
  113. of the MUI system. These gadget related classes are all subclasses of
  114. area class, they describe a rectangle region with some class dependant
  115. contents. Many different classes such as strings, buttons, checkmarks
  116. or listviews are available, but the most important subclass of area
  117. class is probably the group class. Instances of this class are able to
  118. handle any number of child objects and control the size and position of
  119. these children with various attributes. Of course these children can
  120. again be group objects with other sets of children.  Since you usually
  121. want your window to contain more than just one object, the root object
  122. of a window will be a group class object in almost all cases.
  123.  
  124.    Because these first paragraphs are very important to understand how
  125. MUI works, here's a brief summary:
  126.  
  127.    An application consists of exactly one application object. This
  128. application object may have any number of children, each of them being
  129. a window object. Every window object contains a root object, usually of
  130. type group class. This group object again handles any number of child
  131. objects, either other group objects or some user interface elements
  132. such as strings, sliders or buttons.
  133.  
  134.    A little diagram might make things more clear:
  135.  
  136.                                  +-------------+
  137.                                  ! Application !
  138.                                  +-------------+
  139.                                         !
  140.               ... ------+---------------+----------------+
  141.                         !               !                !
  142.                    +--------+       +--------+       +--------+
  143.                    ! Window !       ! Window !       ! Window !
  144.                    +--------+       +--------+       +--------+
  145.                         !               !                !
  146.                     +-------+
  147.                     ! Group !          ...              ...
  148.                     +-------+
  149.                         !
  150.          +------------+-+--------+-----------------+
  151.          !            !          !                 !
  152.      +--------+   +-------+   +------+         +-------+
  153.      ! String !   ! Group !   ! Text !         ! Group !
  154.      +--------+   +-------+   +------+         +-------+
  155.                       !                            !
  156.        ... -----+-----+-----+          +-----------+------- ...
  157.                 !           !          !           !
  158.              +------+   +-------+   +------+   +-------+
  159.              ! List !   ! Cycle !   ! List !   ! Group !
  160.              +------+   +-------+   +------+   +-------+
  161.                                                    !
  162.                                              +-----+-----+
  163.                                              !           !
  164.                                          +--------+  +--------+
  165.                                          ! Button !  ! Button !
  166.                                          +--------+  +--------+
  167.  
  168.    As shown in this tree, only three types of objects are allowed to
  169. have children:
  170.  
  171.      Application: zero or more children of window class.
  172.           Window: exactly one child of any subclass of area class.
  173.            Group: one or more children of any subclass of area class.
  174.  
  175. Object Handling
  176. ===============
  177.  
  178.    Since MUI uses BOOPSI as object oriented programming system, objects
  179. could simply be created using intuition.library/NewObject().  However,
  180. `muimaster.library' also features a generation function called
  181.  
  182.      Object * MUI_NewObjectA(STRPTR class, struct TagItem *taglist);
  183.  
  184. with the varargs stub
  185.      Object * MUI_NewObject(STRPTR class, Tag tag1, ..., TAG_DONE);
  186.  
  187.    That's the function you should use when creating objects of public
  188. MUI classes. The parameter `class' specifies the name of the object's
  189. class (e.g. `MUIC_Window', `MUIC_Slider', ...).  If the needed class
  190. isn't already in memory, it is automatically loaded from disk.
  191.  
  192.    With `taglist', you specify initial create time attributes for your
  193. object. Every attribute from the objects true class or from one of its
  194. super classes is valid here, as long as it's marked with the letter `I'
  195. in the accompanying autodocs documentation.
  196.  
  197.    To create a string object with a string-kind frame, a maximum length
  198. of 80 and the initial contents "foobar", you would have to use the
  199. following command:
  200.  
  201.      MyString = MUI_NewObject(MUIC_String,
  202.                     MUIA_Frame          , MUIV_Frame_String,
  203.                     MUIA_String_Contents, "foobar",
  204.                     MUIA_String_MaxLen  , 80,
  205.                     TAG_DONE);
  206.  
  207.    Once your object is ready, you can start talking to it by setting or
  208. getting one of its attributes or by sending it methods. The standard
  209. BOOPSI functions `SetAttrs()', `GetAttr()' and `DoMethod()' are used
  210. for these purposes:
  211.  
  212.         char *contents;
  213.         SetAttrs(MyString,MUIA_String_Contents,"look",TAG_DONE);
  214.         GetAttr(MUIA_String_Contents,MyString,&contents);
  215.         printf("Always %s on the bright side of life.",contents);
  216.      
  217.         DoMethod(mylist,MUIM_List_Remove,42); /* remove entry nr 42 */
  218.  
  219.    As already mentioned above, all attributes and methods are completely
  220. documented in the autodocs coming with this distribution. These
  221. autodocs follow the usual format, you can parse them with one of the
  222. various tools to create some hypertext online help for your favourite
  223. editor.
  224.  
  225.    When you're done with an object, you should delete it with a call to
  226.  
  227.      VOID MUI_DisposeObject(Object *obj);
  228.  
  229. from `muimaster.library'. After doing so, the object pointer is invalid
  230. and must no longer be used.
  231.  
  232.    When deleting objects, the parent-child connections mentioned above
  233. play an important role. If you dispose an object with children, not
  234. only the object itself but also all of its children (and their
  235. children, and the children of their children ...) get deleted. Since in
  236. a usual MUI application, the application object is the father of every
  237. window, the window is the father of it's contents and every group is
  238. the father of its sub objects, a single dispose of the application
  239. object will free the entire application.
  240.  
  241.    Note well: you may *not* delete objects that are currently children
  242. of other objects. Thus, if you have a complete application tree, the
  243. only thing you can delete is the application object itself as this one
  244. has no father. You can, however, add and remove children dynamically.
  245. More information on that topic follows later in this document.
  246.  
  247. Macros
  248. ======
  249.  
  250.    This chapter is only valid if you use C as your MUI programming
  251. language. Other language interfaces might feature other types of macros
  252. or support functions. Please have a look at the supplied interfaces to
  253. see how they work.
  254.  
  255.    The tree structure that builds up an application also appears in the
  256. source code of a MUI program. Since adding child objects is always
  257. possible with a special attribute of the parent object, it is common to
  258. create the whole tree with one big function call.
  259.  
  260.    To help making these calls more clear, the MUI header files contain
  261. several macros that simplify the task of object generation.
  262.  
  263.    Instead of
  264.  
  265.      MUI_NewObject(MUIC_Window, ..., TAG_DONE);
  266.      MUI_NewObject(MUIC_String, ..., TAG_DONE);
  267.      MUI_NewObject(MUIC_Slider, ..., TAG_DONE);
  268.  
  269. you can simply use
  270.  
  271.      WindowObject, ..., End;
  272.      StringObject, ..., End;
  273.      SliderObject, ..., End;
  274.  
  275.    Please note that the `xxxObject' macros contain an opening bracket
  276. and thus must always be terminated with an `End' macro that contains
  277. the matching closing bracket.
  278.  
  279.    Besides these "two way" macros, there are also some complete object
  280. definitions available which all create specific objects with certain
  281. types of attributes. The macro
  282.  
  283.      SimpleButton("Cancel")
  284.  
  285. would e.g. generate a complete button object with the correct frame,
  286. background and input capabilities. Though lots of these types of macros
  287. are available and can of course be used directly in your applications,
  288. they are mainly intended as some kind of example. Usually you will need
  289. some more sophisticated generation capabilities with a more specific
  290. set of macros.
  291.  
  292.    Note: If your application needs lots of objects from a specific type
  293. (e.g. 200 buttons), you can save some memory by turning macros into
  294. functions.
  295.  
  296. Layout Engine
  297. *************
  298.  
  299. Overview
  300. ========
  301.  
  302.    One of the most important and powerful features of MUI is its dynamic
  303. layout engine. As opposed to other available user interface tools, the
  304. programmer of a MUI application doesn't have to care about gadget sizes
  305. and positions. MUI handles all necessary calculations automatically,
  306. making every program completely screen, window size and font sensitive
  307. without the need for the slightest programmer interaction.
  308.  
  309.    From a programmers point of view, all you have to do is to define
  310. some rectangle areas that shall contain the objects you want to see in
  311. your window. Objects of group class are used for this purpose. These
  312. objects are not visible themselves, but instead tell their children
  313. whether they should appear horizontally or vertically (there are more
  314. sophisticated layout possibilities, more on this later).
  315.  
  316.    For automatic and dynamic layout, it's important that every single
  317. object knows about its minimum and maximum dimensions. Before opening a
  318. window, MUI asks all its gadgets about these values and uses them to
  319. calculate the windows extreme sizes.
  320.  
  321.    Once the window is opened, layout takes place. Starting with the
  322. current window size, the root object and all its children are placed
  323. depending on the type of their father's group and on some additional
  324. attributes.  The algorithm ensures that objects will never become
  325. smaller as their minimum or larger as their maximum size.
  326.  
  327.    The important thing with this mechanism is that object placement
  328. depends on window size. This allows very easy implementation of a
  329. sizing gadget: whenever the user resizes a window, MUI simply starts a
  330. new layout process and recalculates object positions and sizes
  331. automatically. No programmer interaction is needed.
  332.  
  333. Groups
  334. ======
  335.  
  336.    As mentioned above, a programmer specifies a windows outfit by
  337. grouping objects either horizontally or vertically. As a little
  338. example, lets have a look at a simple file requester window:
  339.  
  340.      +---------------------------------------+
  341.      !                                       !
  342.      !  +------------------------+ +------+  !
  343.      !  ! C                (dir) ! ! dh0: !  !
  344.      !  ! Classes          (dir) ! ! dh1: !  !
  345.      !  ! Devs             (dir) ! ! dh2: !  !
  346.      !  ! Expansion        (dir) ! ! df0: !  !
  347.      !  ! ...                    ! ! df1: !  !
  348.      !  ! Trashcan.info    1.172 ! ! df2: !  !
  349.      !  ! Utilities.info     632 ! ! ram: !  !
  350.      !  ! WBStartup.info     632 ! ! rad: !  !
  351.      !  +------------------------+ +------+  !
  352.      !                                       !
  353.      !  Path: _____________________________  !
  354.      !                                       !
  355.      !  File: _____________________________  !
  356.      !                                       !
  357.      !  +------+                 +--------+  !
  358.      !  ! Okay !                 ! Cancel !  !
  359.      !  +------+                 +--------+  !
  360.      !                                       !
  361.      +---------------------------------------+
  362.  
  363.    This window consists of two listview objects, two string gadgets and
  364. two buttons. To tell MUI how these objects shall be placed, you need to
  365. define groups around them. Here, the window consists of a vertical group
  366. that contains a horizontal group with both lists as first child, the
  367. path gadget as second child, the file gadget as third child and again a
  368. horizontal group with both buttons as fourth child.
  369.  
  370.    Using the previously defined macro language, the specification could
  371. look like this (in this example, `VGroup' creates a vertical group and
  372. `HGroup' creates a horizontal group):
  373.  
  374.      VGroup,
  375.         Child, HGroup,
  376.            Child, FileListview(),
  377.            Child, DeviceListview(),
  378.            End,
  379.         Child, PathGadget(),
  380.         Child, FileGadget(),
  381.         Child, HGroup,
  382.            Child, OkayButton(),
  383.            Child, CancelButton(),
  384.            End,
  385.         End;
  386.  
  387.    This tiny piece of source is completely enough to define the
  388. contents of a window, all necessary sizes and positions are
  389. automatically calculated by the MUI system.
  390.  
  391.    To understand how these calculations work, it's important to know
  392. that all basic objects (e.g. strings, buttons, lists) have a fixed
  393. minimum and a maximum size. Group objects calculate their minimum and
  394. maximum sizes from their children, depending whether they are
  395. horizontal or vertical:
  396.  
  397.    - Horizontal groups
  398.  
  399.      The minimum width of a horizontal group is the sum of all minimum
  400.      widths of its children.
  401.  
  402.      The maximum width of a horizontal group is the sum of all maximum
  403.      widths of its children.
  404.  
  405.      The minimum height of a horizontal group is the biggest minimum
  406.      height of its children.
  407.  
  408.      The maximum height of a horizontal group is the smallest maximum
  409.      height of its children.
  410.  
  411.    - Vertical groups
  412.  
  413.      The minimum height of a vertical group is the sum of all minimum
  414.      heights of its children.
  415.  
  416.      The maximum height of a vertical group is the sum of all maximum
  417.      heights of its children.
  418.  
  419.      The minimum width of a vertical group is the biggest minimum width
  420.      of its children.
  421.  
  422.      The maximum width of a vertical group is the smallest maximum
  423.      width of its children.
  424.  
  425.    Maybe this algorithm sounds a little complicated, but in fact it is
  426. really straight forward and ensures that objects will neither get
  427. smaller as their minimum nor bigger as their maximum size.
  428.  
  429.    Before a window is opened, it asks its root object (usually a group
  430. object) to calculate minimum and maximum sizes. These sizes are used as
  431. the windows bounding dimensions, the smallest possible window size will
  432. result in all objects being display in their minimum size.
  433.  
  434.    Once minimum and maximum sizes are calculated, layout process
  435. starts. The root object is told to place itself in the rectangle
  436. defined by the current window size. This window size is either
  437. specified by the programmer or results from a window resize operation
  438. by the user. When an object is told to layout itself, it simply sets
  439. its position and dimensions to the given rectangle.  In case of a group
  440. object, a more or less complicated algorithm distributes all available
  441. space between its children and tells them to layout too.
  442.  
  443.    This "more or less complicated algorithm" is responsible for the
  444. object arrangement. Depending on some attributes of the group object
  445. (horizontal or vertical, ...) and on some attributes of the children
  446. (minimum and maximum dimensions, ...), space is distributed and
  447. children are placed.
  448.  
  449.    A little example makes things more clear. Let's see what happens in
  450. a window that contains nothing but three horizontally grouped
  451. colorfield objects:
  452.  
  453.      +---------------------------------+
  454.      !                                 !
  455.      !  +-------+ +-------+ +-------+  !
  456.      !  !       ! !       ! !       !  !
  457.      !  ! field ! ! field ! ! field !  !
  458.      !  !   1   ! !   2   ! !   3   !  !
  459.      !  !       ! !       ! !       !  !
  460.      !  +-------+ +-------+ +-------+  !
  461.      !                                 !
  462.      +---------------------------------+
  463.  
  464.    Colorfield objects have a minimum width and height of one pixel and
  465. no (in fact a very big) maximum width and height. Since we have a
  466. horizontal group, the minmax calculation explained above yields to a
  467. minimum width of three pixels and a minimum height of one pixel for the
  468. windows root object (the horizontal group containing the colorfields).
  469. Maximum dimensions of the group are unlimited. Using these results, MUI
  470. is able to calculate the windows bounding dimensions by adding some
  471. spacing values and window border thicknesses.
  472.  
  473.    Once min and max dimensions are calculated, the window can be opened
  474. with a programmer or user specified size. This size is the starting
  475. point for the following layout calculations. For our little example,
  476. let's imagine that the current window size is 100 pixels wide and 50
  477. pixels high.
  478.  
  479.    MUI subtracts the window borders and some window inner spacing and
  480. tells the root object to layout itself into the rectangle left=5,
  481. top=20, width=90, height=74. Since our root object is a horizontal
  482. group in this case, it knows that each colorfield can get the full
  483. height of 74 pixels and that the available width of 90 pixels needs to
  484. be shared by all three fields.  Thus, the resulting fields will all get
  485. a width of 90/3=30 pixels.
  486.  
  487.    That's the basic way MUI's layout system works. There are a lot more
  488. possibilities to influence layout, you can e.g.  assign different
  489. weights to objects, define some inter object spacing or even make
  490. two-dimensional groups. These sophisticated layout issues are discussed
  491. in the autodocs of group class.
  492.  
  493. Building An Application
  494. ***********************
  495.  
  496. Creation
  497. ========
  498.  
  499.    Creating all the objects that make up an applications user interface
  500. is usually done with one big `MUI_NewObject()' call. This call returns
  501. a pointer to the application object as its result and contains lots of
  502. other object creation calls as parameter for its tag items. Using the
  503. previously defined macro language, a sample generation call could look
  504. like this:
  505.  
  506.      app = ApplicationObject,
  507.         MUIA_Application_Title      , "Settings",
  508.         MUIA_Application_Version    , "$VER: Settings 6.16 (20.10.93)",
  509.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  510.         MUIA_Application_Author     , "Stefan Stuntz",
  511.         MUIA_Application_Description, "Just a silly demo",
  512.         MUIA_Application_Base       , "SETTINGS",
  513.      
  514.         SubWindow, window1 = WindowObject,
  515.            MUIA_Window_Title, "Save/use me and start me again!",
  516.            MUIA_Window_ID   , MAKE_ID('S','E','T','T'),
  517.      
  518.            WindowContents, VGroup,
  519.      
  520.               Child, ColGroup(2), GroupFrameT("User Identification"),
  521.                  Child, Label2("Name:"  ), Child, str1 = String(0,40),
  522.                  Child, Label2("Street:"), Child, str2 = String(0,40),
  523.                  Child, Label2("City:"  ), Child, str3 = String(0,40),
  524.                  Child, Label1("Passwd:"), Child, str4 = String(0,40),
  525.                  Child, Label1("Sex:"   ), Child, str5 = String(0,40),
  526.                  Child, Label("Age:"),
  527.                  Child, sl  = SliderObject, End,
  528.                  End,
  529.      
  530.               Child, VSpace(2),
  531.      
  532.               Child, HGroup,
  533.                  MUIA_Group_SameSize, TRUE,
  534.                  Child, btsave   = KeyButton("Save"  ,'s'),
  535.                  Child, btuse    = KeyButton("Use"   ,'u'),
  536.                  Child, btcancel = KeyButton("Cancel",'>'),
  537.                  End,
  538.      
  539.               End,
  540.            End,
  541.      
  542.         SubWindow, window2 = WindowObject,
  543.            MUIA_Window_Title, "Window 2",
  544.            ...,
  545.            ...,
  546.            End,
  547.      
  548.         SubWindow,
  549.            ...
  550.            End,
  551.      
  552.         End;
  553.      
  554.      if (!app) fail(app,"Failed to create Application.");
  555.  
  556.    This big structure is indeed one single function call that builds a
  557. lot of other objects on the fly. Windows are created as children of the
  558. application object, a windows contents are created as child of the
  559. window and a groups contents are created as children of the group.
  560.  
  561.    Though many single objects are created, error handling is very easy.
  562. When a parent object encounters a NULL pointer supplied as one of its
  563. children, it will automatically dispose all other supplied children and
  564. fail too. Thus, even errors occuring in a very deep level will cause
  565. the complete application object to fail.  On the other hand, if you
  566. receive a non NULL application pointer, you can be sure that all other
  567. objects have successfully been created.
  568.  
  569.    Once you're done with your application, a single
  570.  
  571.      MUI_DisposeObject(app);
  572.  
  573. is enough to get rid of all previously created objects.
  574.  
  575. Notificiation
  576. =============
  577.  
  578.    The central element for controlling a MUI application is the
  579. notification mechanism. To understand how it works, its important to
  580. know that most objects feature lots of attributes that define their
  581. current state. Notification makes it possible to react on changes of
  582. these attributes.
  583.  
  584.    Attributes are changed either directly by the programmer (with a
  585. call to SetAttrs()) or by the user manipulation some gadgets.  If he
  586. e.g. drags around the knob of a proportional gadget, the
  587. MUIA_Prop_First attribute will continously be updated and reflect the
  588. current position.
  589.  
  590.    With notification, you could directly use this attribute change to
  591. set the MUIA_List_TopPixel attribute of a list object, building up a
  592. full featured listview:
  593.  
  594.      DoMethod(sbar, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime,
  595.               list, 3, MUIM_Set, MUIA_List_TopPixel, MUIV_TriggerValue);
  596.  
  597.    To make it clear: Every time, the scrollbar object changes its
  598. `MUIA_Prop_First' value, the list object shall change its
  599. `MUIA_List_TopPixel' attribute accordingly. The value 3 in the above
  600. function call identifies the number of the following parameters. Since
  601. you can call any method with any parameters here and MUI needs to save
  602. it somewhere, it's important to set it correctly.
  603.  
  604.    From now on the list and the scrollbar are connected to each other.
  605. As soon as the proportional gadget is moved, the position of the list
  606. changes accordingly; the programmer doesn't have to care about.
  607.  
  608.    Notification is mostly used together with either the
  609. `MUIM_Application_ReturnID' or with the `MUIM_CallHook' method. If you
  610. e.g. have a specific hook that should be called whenever the user
  611. presses a button, you could use the following notify method:
  612.  
  613.      DoMethod(button, MUIM_Notify, MUIA_Button_Pressed, FALSE,
  614.               button, 2, MUIM_CallHook, &ButtonHook);
  615.      
  616.      /* Whenever the button's pressed attribute is set to FALSE
  617.         (i.e. the user has released the button), the button object
  618.         itself will call ButtonHook. */
  619.  
  620.    Futher information can be found in the autodocs of notify class.
  621.  
  622. Dynamic Object Linking
  623. **********************
  624.  
  625. Overview
  626. ========
  627.  
  628.    Usually, the complete user interface of an application is created
  629. with one single command. This makes error handling very easy and allows
  630. parallel usage of several windows. However, sometimes it makes sense to
  631. create certain windows only when they are actually needed: For example,
  632. if an application supplies many subwindows and would use too much
  633. memory, or if the number and contents of needed windows is not known at
  634. application startup time.
  635.  
  636.    Therefore MUI supports the option of "late binding".  Using this
  637. mechanism, children can be added and removed after their parent object
  638. already has been created. MUI uses the methods `OM_ADDMEMBER' and
  639. `OM_REMMEMBER' for this purpose:
  640.  
  641.      DoMethod(parent,OM_ADDMEMBER,child); /* add child object    */
  642.      DoMethod(parent,OM_REMMEMBER,child); /* remove child object */
  643.  
  644.    Both methods are only supported by MUI's application and group
  645. class; these are the only classes that can manage several children.
  646. Dynamic object linking for window and group class is explained in
  647. detail in the following chapters.
  648.  
  649.    Note: Objects that do not have parents, be it, because they are not
  650. yet connected using `OM_ADDMEMBER' or because they were disconnected
  651. using `OM_REMMEMBER', it's the programmer's task to delete them by
  652. calling `MUI_DisposeObject()'.  On the other side, objects that still
  653. are children of other objects must not be deleted!
  654.  
  655. Dynamic Windows
  656. ===============
  657.  
  658.    Let's say an application object is already set up and another (not
  659. yet existing) window has to be added. First, the window object needs to
  660. be created:
  661.  
  662.      win = WindowObject,
  663.         MUIA_Window_Title, "New Window",
  664.            WindowContents, VGroup,
  665.               Child, ...,
  666.               Child, ...,
  667.               Child, ...,
  668.               End,
  669.            End,
  670.         End;
  671.      
  672.      if (!win) fail(); /* failure check */
  673.  
  674. After the window object is created, it can be added to the application
  675. as one of its children:
  676.  
  677.      DoMethod(app,OM_ADDMEMBER,win);
  678.  
  679.    Now this window has become a part of the application, just as if it
  680. had been created as a subwindow together with the application object.
  681. It can be opened and closed by setting the according attributes and
  682. will be deleted automatically as soon as the application is ended.
  683.  
  684.    Usually, however, you'll want to delete this window directly after
  685. usage, because the late binding wouldn't make much sense otherwise.
  686.  
  687. After closing the window via
  688.  
  689.      set(win,MUIA_Window_Open,FALSE);
  690.  
  691. you can remove it by calling
  692.  
  693.      DoMethod(app,OM_REMMEMBER,win);
  694.  
  695.    After this you have to delete the window object "by hand", since the
  696. application no longer knows of it:
  697.  
  698.      MUI_DisposeObject(win);
  699.  
  700.    This method makes it possible to create subroutines that open their
  701. own window, wait for some imput events und return something.
  702.  
  703. To illustrate this, here is a short example:
  704.  
  705.      set(app,MUIA_Application_Sleep,TRUE);  // disable other windows
  706.      
  707.      win = WindowObject, ...., End;         // create new window
  708.      
  709.      if (win)                               // ok ?
  710.      {
  711.          DoMethod(app,OM_ADDMEMBER,win);    // add window...
  712.          set(win,MUIA_Window_Open,TRUE);    // and open it
  713.      
  714.          while (running)
  715.          {
  716.              switch (DoMethod(app,MUIM_Application_Input,&sigs))
  717.              {
  718.                  ... // Extra Input loop. For this window only.
  719.                  ... // Note: The special value
  720.                  ... // MUIV_Application_ReturnID_Quit should be recognized
  721.                  ... // as well
  722.              }
  723.          }
  724.      
  725.          set(win,MUIA_Window_Open,FALSE);   // Close window
  726.      
  727.          DoMethod(app,OM_REMMEMBER,win);    // remove
  728.      
  729.          MUI_DisposeObject(win);            // and kill it
  730.      }
  731.      
  732.      set(app,MUIA_Application_Sleep,FALSE); // wake up the application
  733.  
  734. Dynamic Groups
  735. ==============
  736.  
  737.    In the same way you can add windows to an application after its
  738. creation, you can add elements to already existing group objects. This
  739. may be useful if a group contains many similar children or if the
  740. number of children is not known in the beginning.
  741.  
  742.    You can add new elements to groups or delete them again, but the
  743. window that contains this group must not be open!
  744.  
  745. A small example:
  746.  
  747.          app = ApplicationObject,
  748.              ...,
  749.              SubWindow, win = WindowObject,
  750.                  WindowContents, VGroup,
  751.                      ...,
  752.                      grp = VGroup,
  753.                  End,
  754.                  ...,
  755.              End,
  756.          End,
  757.      End;
  758.      
  759.      /* The group 'grp' has been created without any children. */
  760.      /* The window must not be opened now!                     */
  761.      
  762.      for (i=0; i<NumPlayers; i++)
  763.      {
  764.         Object *name = StringObject, MUIA_String_MaxLen, 30, End;
  765.         if (name)
  766.            DoMethod(grp,OM_ADDMEMBER,name); // add gadget to group.
  767.         else
  768.            fail();
  769.      }
  770.      
  771.      /* After we have at least one element in the group 'grp', */
  772.      /* the window can be opened...                            */
  773.  
  774.    Of course you may (if the window is closed) remove elements from
  775. groups. Please note that window objects containing empty groups must
  776. not be opened.
  777.  
  778. Custom Classes
  779. **************
  780.  
  781. Introduction
  782. ============
  783.  
  784.    MUI features a lot of builtin classes that already allow creation of
  785. powerful applications. However, a generic GUI system will never be able
  786. to satisfy all the requirements of all kinds of programs. A sound
  787. editor would e.g. need a class to display and edit sound data, a paint
  788. program would need a drawing area and a chess game would need a
  789. chess-board class.
  790.  
  791.    Prior to MUI V2.0, programmers were stuck with the builtin classes.
  792. Except of the (sometimes problematic) BOOPSI interface, there was no
  793. way to include custom gadgets in a MUI window. This big disadvantage
  794. has finally disappeared, with MUI 2.0 it's posssible to write and use
  795. private classes just like one of the builtins.
  796.  
  797.    Beneath the BOOPSI gadget interface, private classes are the only
  798. way to have custom gadgets in a MUI window. Drawing into windows
  799. directly from the applications task is illegal and will surely lead
  800. into lots of problems!
  801.  
  802.    Note: Since this manual doesn't repeat the RKMs BOOPSI section, you
  803. should be familiar with the BOOPSI mechanisms of dispatchers, methods,
  804. attributes, instance data structures, etc. before going on.
  805.  
  806. Overview
  807. ========
  808.  
  809.    Building a class is rather simple. All you have to do is to write a
  810. class dispatcher function, setup a hook structure, call MUI_GetClass()
  811. to find the pointer to your superclass and use
  812. intuition.library/MakeClass() to create the class. If you already wrote
  813. BOOPSI classes, you should know whats going on here.
  814.  
  815.    Objects from custom classes are created using intuition.library /
  816. NewObject(), not muimaster.library / MUI_NewObject(). Nevertheless, you
  817. can use these objects like every other MUI objects, e.g. as children of
  818. groups, in virtual groups or wherever you like.
  819.  
  820.    All classes you create have to be subclasses of MUI's area class,
  821. most of them will probably be direct subclasses but you can also have
  822. subclasses of list class or even subclasses of your own classes if you
  823. want. Here's an example of how a custom class could be generated:
  824.  
  825.         /* Get a pointer to the superclass. MUI will lock this */
  826.         /* and prevent it from being flushed during you hold   */
  827.         /* the pointer. When you're done, you have to call     */
  828.         /* MUI_FreeClass() to release this lock.               */
  829.      
  830.         if (!(SuperClass=MUI_GetClass(MUIC_Area)))
  831.            fail("Superclass for the new class not found.");
  832.      
  833.         /* Create the new class with the boopsi function call. */
  834.         /* You will need the sizeof your classes instance data */
  835.         /* here.                                               */
  836.      
  837.         if (!(MyClass = MakeClass(NULL,NULL,SuperClass,sizeof(struct MyData),0)))
  838.         {
  839.            MUI_FreeClass(SuperClass);
  840.            fail("Failed to create class.");
  841.         }
  842.      
  843.         /* Set the dispatcher for the new class. */
  844.      
  845.         MyClass->cl_Dispatcher.h_Entry    = (APTR)MyDispatcher;
  846.         MyClass->cl_Dispatcher.h_SubEntry = NULL;
  847.         MyClass->cl_Dispatcher.h_Data     = NULL;
  848.      
  849.         ...
  850.         ...
  851.      
  852.         app = ApplicationObject,
  853.            ...,
  854.      
  855.            SubWindow, window = WindowObject,
  856.               ...
  857.               WindowContents, VGroup,
  858.      
  859.                  Child, MyObj = NewObject(MyClass,NULL,
  860.                     TextFrame,
  861.                     MUIA_Background, MUII_BACKGROUND,
  862.                     TAG_DONE),
  863.      
  864.                  End,
  865.      
  866.               End,
  867.            End;
  868.      
  869.         ...
  870.         ...
  871.      
  872.         /* Shutdown. When the application is disposed,
  873.         /* MUI also deletes MyObj. */
  874.      
  875.         MUI_DisposeObject(app);     // dispose all objects.
  876.         FreeClass(MyClass);         // free our private class.
  877.         MUI_FreeClass(SuperClass);  // release super class pointer.
  878.  
  879.    You're dispatcher will look like a traditional BOOPSI dispatcher:
  880.  
  881.      SAVEDS ASM ULONG MyDispatcher(
  882.         REG(a0) struct IClass *cl,
  883.         REG(a2) Object *obj,
  884.         REG(a1) Msg msg)
  885.      {
  886.         switch (msg->MethodID)
  887.         {
  888.            case OM_NEW        : return(mNew      (cl,obj,(APTR)msg));
  889.            case OM_DISPOSE    : return(mDispose  (cl,obj,(APTR)msg));
  890.            case MUIM_AskMinMax: return(mAskMinMax(cl,obj,(APTR)msg));
  891.            case MUIM_Draw     : return(mDraw     (cl,obj,(APTR)msg));
  892.            ...
  893.         }
  894.      
  895.         return(DoSuperMethodA(cl,obj,msg));
  896.      }
  897.  
  898.    What methods are available and need to be supported is discussed in
  899. the following chapter.
  900.  
  901.    Note: Your dispatcher will also receive some undocumented methods.
  902. It's not a wise choice to make any assumptions here, the only thing you
  903. should do is pass them to your superclass immediately!
  904.  
  905. Methods
  906. =======
  907.  
  908.    The MUI system talks to its classes with a specific set of methods.
  909. Some of these methods need to be implemented by all MUI classes but
  910. most of them are optional.  This chapter gives a quick overview about
  911. the methods your class might receive.  All methods are discussed more
  912. detailed in the following sections.
  913.  
  914.    As usual with BOOPSI objects, you will get an OM_NEW whenever a new
  915. object of your class shall be created. Since with MUI, the deepest
  916. nested objects are always created first, your object won't know anything
  917. about its display environment during OM_NEW.
  918.  
  919.    After all objects are created, MUI finds out about the display
  920. environment (screen, drawinfo structure, fonts, etc.) and sends you a
  921. MUIM_Setup method with this information. You can calculate some
  922. internal data here that depends on the display enviroment (e.g. the
  923. line height in an editor class). Note that you still don't have a
  924. intuition window at this point.
  925.  
  926.    The next method your class receives is called MUIM_AskMinMax. MUI
  927. wants to find out about your minimum, maximum and default sizes to
  928. prepare its window size calculation and layout algorithms. Since you
  929. already know about display environment, calculating these values should
  930. be easy at this point.
  931.  
  932.    After asking all objects about their dimensions and adding the
  933. results depending on the type of group your object resides in, MUI is
  934. able to open the window. Once it is open, your object will receive a
  935. MUIM_Show method telling you that you are about to be added to the
  936. window.  MUIM_Show is mainly intended for use by intuition like
  937. gadgets, they will do an AddGadget() here (and a RemGadget() during
  938. MUIM_Hide). Usually, you won't need to implement these methods.
  939.  
  940.    Since your class still didn't draw anything, its time for a
  941. MUIM_Draw method now. MUI sends this method whenever it feels that you
  942. should draw yourself.  This happens of course after a window has been
  943. opened but also when you reside in a simple refresh window and need to
  944. be refreshed. MUIM_Draw is the only place where you are actually
  945. allowed to draw something!
  946.  
  947.    When the window is resized, MUI sends a MUIM_Hide (allowing some
  948. RemGadget() for intuition like gadgets), calculates new positions and
  949. sizes and sends a MUIM_Show and a MUIM_Draw again. However, if you
  950. correctly implement MUIM_Draw, you don't need to care about this in
  951. almost all cases.
  952.  
  953.    When your window is about to be closed (either because your
  954. application no longer needs it or because the user iconified your
  955. program or changed the preferences settings), you will receive a
  956. MUIM_Cleanup. This allows you to free some display environment
  957. dependant things you allocated during MUIM_Setup.
  958.  
  959.    The last thing your object will get is of course a OM_DISPOSE after
  960. it has hopefully done all the things you wanted it to do.
  961.  
  962.    To sum it up again, look at the diagram below. Things between
  963. brackets might be called zero or more times for the same object.
  964.  
  965.      OM_NEW; /* you dont know anything about display environment here */
  966.      {
  967.         MUIM_Setup;      /* information about display, still no window */
  968.         MUIM_AskMinMax;  /* tell me your min/max dimensions */
  969.         [ window is opened here ]
  970.         {
  971.            MUIM_Show;    /* add yourself to the window, don't yet draw */
  972.            {
  973.               MUIM_Draw;     /* draw yourself */
  974.            }
  975.            MUIM_Hide;    /* remove yourself from the window */
  976.         }
  977.         [ window is closed here ]
  978.         MUIM_Cleanup;    /* free any display dependant data */
  979.      }
  980.      OM_DISPOSE; /* kill yourself completely */
  981.  
  982.    As you probably noticed, most methods are implemented as
  983. constructor/destructor pairs: OM_NEW & OM_DISPOSE, MUIM_Setup &
  984. MUIM_Cleanup, MUIM_Show & MUIM_Hide. For every constuctor call, you
  985. will receive exactly one destructor call. Usually, you will allocate
  986. some resources during OM_NEW, MUIM_Setup or MUIM_Show and free these
  987. resources during OM_DISPOSE, MUIM_Cleanup or MUIM_Hide respectively.
  988.  
  989.    The three levels of constructor/destructor pairs feature different
  990. amount of available information about the display environment.
  991.  
  992.    - OM_NEW (destructor OM_DISPOSE)
  993.  
  994.      No information at all. All you can do is parse the initial
  995.      attribute list and store its contents in the instance data
  996.      structure of your object.
  997.  
  998.    - MUIM_Setup (destructor MUIM_Cleanup)
  999.  
  1000.      MUI has figured out what screen and font to use. You can
  1001.      allocate/calculate things that depend on this information.
  1002.  
  1003.    - MUIM_Show (destructor MUIM_Hide)
  1004.  
  1005.      MUI has finally opened an intuition window at this point. You are
  1006.      able to allocate resources depending on a window context here.
  1007.  
  1008.    You can rely on the fact that you receive OM_NEW before MUIM_Setup
  1009. (of course, otherwise you wouldn't have a valid object pointer) and
  1010. MUIM_Setup before MUIM_Show. But always keep in mind that you might get
  1011. multiple MUIM_Show / MUIM_Hide pairs or MUIM_Setup / MUIM_Cleanup pairs
  1012. or that you could receive a MUIM_Setup / MUIM_Cleanup pair without some
  1013. MUIM_Show / MUIM_Hide between.
  1014.  
  1015. OM_NEW & OM_DISPOSE
  1016. ===================
  1017.  
  1018.    Implementing these methods for MUI objects is mainly identical to
  1019. traditional BOOPSI objects. The only thing important to remember is
  1020. that MUI objects have really no idea about display environment or other
  1021. configuration issues when receiving OM_NEW. The ops_GInfo member of the
  1022. opSet parameter structure is always unused.  Typical new/dispose
  1023. methods consist of some tag list parsing and instance data
  1024. initialisation.
  1025.  
  1026.  
  1027.      static ULONG mNew(struct IClass *cl,Object *obj,struct opSet *msg)
  1028.      {
  1029.         struct INST_DATA *data;
  1030.      
  1031.         if (!(obj = (Object *)DoSuperMethodA(cl,obj,msg)))
  1032.            return(0);
  1033.      
  1034.         data = INST_DATA(cl,obj);
  1035.      
  1036.         data->min = GetTagData(MYATTR_Min,  0,msg->ops_AttrList);
  1037.         data->max = GetTagData(MYATTR_Max,100,msg->ops_AttrList);
  1038.         data->lvl = GetTagData(MYATTR_Lvl, 50,msg->ops_AttrList);
  1039.      
  1040.         data->count  = data->max - data->min + 1;
  1041.         data->buffer = NULL;
  1042.      
  1043.         if (data->count > 0)
  1044.         {
  1045.            if (data->buffer = AllocVec(data->count * 4))
  1046.            {
  1047.               return((ULONG)obj);
  1048.            }
  1049.         }
  1050.      
  1051.         /* invoke OM_DISPOSE on *our* class! */
  1052.         CoerceMethod(cl,obj,OM_DISPOSE);
  1053.         return(0);
  1054.      }
  1055.      
  1056.      
  1057.      static ULONG mDispose(struct IClass *cl,Object *obj,Msg msg)
  1058.      {
  1059.         struct Data *data = INST_DATA(cl,obj);
  1060.      
  1061.         if (data->buffer) FreeVec(data->buffer);
  1062.      
  1063.         return(DoSuperMethodA(cl,obj));
  1064.      }
  1065.  
  1066. MUIM_Setup & MUIM_Cleanup
  1067. =========================
  1068.  
  1069.    Since your object doesn't know anything about display environment
  1070. after it is created with OM_NEW, MUI will send you an MUIM_Setup when
  1071. it is about to open a window containing your object.
  1072.  
  1073.    The first thing you have to do is to pass MUIM_Setup to your super
  1074. class an return FALSE on failure. After this, you can calculate some
  1075. internal data or allocate some display buffers. Return TRUE if
  1076. everything went ok or FALSE when you discovered any errors. In this
  1077. case, MUI will send a MUIM_Cleanup to all objects that already received
  1078. a MUIM_Setup (excluding the current one!) and fail to open the window.
  1079. Typical setup/cleanup pairs could look like this:
  1080.  
  1081.  
  1082.      static ULONG mSetup(struct IClass *cl,Object *obj,Msg msg)
  1083.      {
  1084.         struct Data *data = INST_DATA(cl,obj);
  1085.      
  1086.         if (!(DoSuperMethodA(cl,obj,msg)))
  1087.            return(FALSE);
  1088.      
  1089.         data->lineheight = _font(obj)->tf_YSize;
  1090.      
  1091.         if (!(data->linebuf = AllocVec(data->count*data->lineheight)))
  1092.            return(FALSE);
  1093.      
  1094.         MUI_RequestIDCMP(obj,IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_INACTIVEWINDOW);
  1095.      
  1096.         return(TRUE);
  1097.      }
  1098.      
  1099.      
  1100.      static ULONG mCleanup(struct IClass *cl,Object *obj,Msg msg)
  1101.      {
  1102.         struct Data *data = INST_DATA(cl,obj);
  1103.      
  1104.         FreeVec(data->linebuf);
  1105.      
  1106.         MUI_RejectIDCMP(obj,IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_INACTIVEWINDOW);
  1107.      
  1108.         return(DoSuperMethodA(cl,obj));
  1109.      }
  1110.  
  1111. MUIM_AskMinMax
  1112. ==============
  1113.  
  1114.    With MUIM_AskMinMax, MUI wants to find out about the minimum,
  1115. maximum and default sizes of your object. These values are needed for
  1116. the correct layout, depending on the type of group that contains your
  1117. object.
  1118.  
  1119.  
  1120.      static ULONG mAskMinMax(
  1121.         struct IClass *cl,
  1122.         Object *obj,
  1123.         struct MUIP_AskMinMax *msg)
  1124.      {
  1125.         /*
  1126.         ** let our superclass first fill in what it thinks about sizes.
  1127.         ** this will e.g. add the size of frame and inner spacing.
  1128.         */
  1129.      
  1130.         DoSuperMethodA(cl,obj,msg);
  1131.      
  1132.         /*
  1133.         ** now add the values specific to our object. note that we
  1134.         ** indeed need to *add* these values, not just set them!
  1135.         */
  1136.      
  1137.         /* x-size depending on objects font */
  1138.         msg->MinMaxInfo->MinWidth  += _font(obj)->tf_XSize * 10;
  1139.         msg->MinMaxInfo->DefWidth  += _font(obj)->tf_XSize * 20;
  1140.         msg->MinMaxInfo->MaxWidth  += MAXMAX; /* unlimited */
  1141.      
  1142.         /* fixed y-size */
  1143.         msg->MinMaxInfo->MinHeight += _font(obj)->tf_YSize;
  1144.         msg->MinMaxInfo->DefHeight += _font(obj)->tf_YSize;
  1145.         msg->MinMaxInfo->MaxHeight += _font(obj)->tf_YSize;
  1146.      
  1147.         return(0);
  1148.      }
  1149.  
  1150. MUIM_Show & MUIM_Hide
  1151. =====================
  1152.  
  1153.    Once the window is opened, your object will receive a MUIM_Show. If
  1154. you have some window/rastport environment dependant things to do,
  1155. MUIM_Show is the correct place. Intuition like gadgets would for
  1156. example do an AddGadget() here.
  1157.  
  1158.    Note that you should *not* render during MUIM_Show. Usually, MUI
  1159. classes won't need to implement this method.
  1160.  
  1161. MUIM_Draw
  1162. =========
  1163.  
  1164.    Whenever MUI feels that your object should render itself, it sends
  1165. you a MUIM_Draw method. This happens e.g. when a window is openend for
  1166. the first time, after a window was resized or when a simple refresh
  1167. window needs to be refreshed. In the latter case, MUI already set up a
  1168. clip region to restrict rendering to the necessary areas.
  1169.  
  1170.    Together with MUIM_Draw comes a flag value that indicates which
  1171. parts of the object are to be redrawn. The only interesting bits in
  1172. this flag value are MADF_DRAWOBJECT and MADF_UPDATE. When
  1173. MADF_DRAWOBJECT is set, MUI wants you to do a complete redraw of your
  1174. object. MADF_UPDATE is not used by the MUI system itself but is
  1175. reserved for your private requirements width the MUI_Redraw() function
  1176. call. See the example programs coming with the MUI distribution for
  1177. details.
  1178.  
  1179.    Information about rendering environment (screen, window, rastport,
  1180. pens, etc.) is saved in a structure called MUI_RenderInfo. Every
  1181. objects render info structure is accessable with the muiRenderInfo(obj)
  1182. macro. Parts of this structure are valid between MUIM_Setup and
  1183. MUIM_Cleanup, other parts like window and rastport pointer are valid
  1184. between MUIM_Show and MUIM_Hide. Please have a look at the supplied
  1185. compiler headers for more detailed information about the MUI_RenderInfo
  1186. structure.
  1187.  
  1188.    Note: MUIM_Draw is the only place where you are allowed to render!
  1189.  
  1190. MUIM_HandleInput
  1191. ================
  1192.  
  1193.    Compared with BOOPSI, MUI uses a different input handling scheme. Not
  1194. only the "active" object but instead all objects may receive input
  1195. events at the same time. Since sending input events to every object in
  1196. a window would be an incredible overhead, you have to specify what
  1197. messages you really need. MUI offers the library calls
  1198. MUI_RequestIDCMP() and MUI_RejectIDCMP() for this purpose. Whenever an
  1199. arriving input event matches your request, your object will receive a
  1200. MUIM_HandleInput method.
  1201.  
  1202.    You can call MUI_RequestIDCMP() and MUI_RejectIDCMP() at every time.
  1203. Performance affecting critical events like INTUITICKS and MOUSEMOVEs
  1204. should only be requested when you really need them. The "Class3" for
  1205. example requests MOUSEBUTTONS and RAWKEY during MUIM_Setup. The critical
  1206. MOUSEMOVES are only requested when a button was pressed and immediately
  1207. rejected after it was released again.
  1208.  
  1209.    Beneath the struct IntuiMessage, MUIM_HandleInput receives a longword
  1210. describing a MUIKEY as second parameter. If this is set to some other
  1211. value as MUIKEY_NONE, your object is the actve object and the input
  1212. event translated to a user configured keyboard action.
  1213.  
  1214.    MUI will *not* translate input events to your objects coordinates.
  1215. This is up to you. A typical input implementation could look like this:
  1216.  
  1217.  
  1218.      static ULONG mHandleInput(
  1219.         struct IClass *cl,
  1220.         Object *obj,
  1221.         struct MUIP_HandleInput *msg)
  1222.      {
  1223.         #define _between(a,x,b) ((x)>=(a) && (x)<=(b))
  1224.         #define _isinobject(x,y) (_between(_mleft(obj),(x),_mright (obj))\
  1225.                                && _between(_mtop(obj) ,(y),_mbottom(obj)))
  1226.      
  1227.         struct Data *data = INST_DATA(cl,obj);
  1228.      
  1229.         if (msg->muikey)
  1230.         {
  1231.            switch (msg->muikey)
  1232.            {
  1233.               case MUIKEY_LEFT :
  1234.                  data->sx=-1;
  1235.                  MUI_Redraw(obj,MADF_DRAWUPDATE);
  1236.                  break;
  1237.               case MUIKEY_RIGHT:
  1238.                  data->sx= 1;
  1239.                  MUI_Redraw(obj,MADF_DRAWUPDATE);
  1240.                  break;
  1241.               case MUIKEY_UP   :
  1242.                  data->sy=-1;
  1243.                  MUI_Redraw(obj,MADF_DRAWUPDATE);
  1244.                  break;
  1245.               case MUIKEY_DOWN :
  1246.                  data->sy= 1;
  1247.                  MUI_Redraw(obj,MADF_DRAWUPDATE);
  1248.                  break;
  1249.            }
  1250.         }
  1251.      
  1252.         if (msg->imsg)
  1253.         {
  1254.            switch (msg->imsg->Class)
  1255.            {
  1256.               case IDCMP_MOUSEBUTTONS:
  1257.               {
  1258.                  if (msg->imsg->Code==SELECTDOWN)
  1259.                  {
  1260.                     if (_isinobject(msg->imsg->MouseX,msg->imsg->MouseY))
  1261.                     {
  1262.                        data->x = msg->imsg->MouseX;
  1263.                        data->y = msg->imsg->MouseY;
  1264.                        MUI_Redraw(obj,MADF_DRAWUPDATE);
  1265.                        MUI_RequestIDCMP(obj,IDCMP_MOUSEMOVE);
  1266.                     }
  1267.                  }
  1268.                  else
  1269.                     MUI_RejectIDCMP(obj,IDCMP_MOUSEMOVE);
  1270.               }
  1271.               break;
  1272.      
  1273.               case IDCMP_MOUSEMOVE:
  1274.               {
  1275.                  if (_isinobject(msg->imsg->MouseX,msg->imsg->MouseY))
  1276.                  {
  1277.                     data->x = msg->imsg->MouseX;
  1278.                     data->y = msg->imsg->MouseY;
  1279.                     MUI_Redraw(obj,MADF_DRAWUPDATE);
  1280.                  }
  1281.               }
  1282.               break;
  1283.            }
  1284.         }
  1285.      
  1286.         /* passing MUIM_HandleInput to the super class is only necessary
  1287.            if you rely on area class input handling (MUIA_InputMode). */
  1288.      
  1289.         return(0);
  1290.      }
  1291.  
  1292. OM_SETGET
  1293. =========
  1294.  
  1295.    Implementing OM_SET and OM_GET is similar to oldstyle BOOPSI gadgets.
  1296. The only important thing to know about is that you should *not* render
  1297. in a OM_SET (e.g. as a result of an attribute change). Instead, call
  1298. MUI_Redraw() with a MADF_DRAWOBJECT or a MADF_UPDATE flag, MUI will
  1299. then call your objects Draw method.
  1300.  
  1301.  
  1302.      static ULONG mSet(struct IClass *cl,Object *obj,Msg msg)
  1303.      {
  1304.         struct MyData *data = INST_DATA(cl,obj);
  1305.         struct TagItem *tags,*tag;
  1306.      
  1307.         for (tags=((struct opSet *)msg)->ops_AttrList;tag=NextTagItem(&tags);)
  1308.         {
  1309.            switch (tag->ti_Tag)
  1310.            {
  1311.               case MYATTR_PEN:
  1312.                  data->pen = tag->ti_Data;         /* set the new value */
  1313.                  MUI_Redraw(obj,MADF_DRAWOBJECT);  /* complete redraw */
  1314.                  break;
  1315.      
  1316.               case MYATTR_LEVEL:
  1317.                  data->level = tag->ti_Data;       /* set the new value */
  1318.                  MUI_Redraw(obj,MADF_DRAWUPDATE);  /* only update ourselves */
  1319.                  break;
  1320.            }
  1321.         }
  1322.      
  1323.         return(DoSuperMethodA(cl,obj,msg));
  1324.      }
  1325.  
  1326. CSC_DISTRIBUTE
  1327. ==============
  1328.  
  1329.    Usually, you will use custom classes only for your own applications.
  1330. In this case, you won't need to care about the tag values used for your
  1331. private attributes and methods. The only thing you should consider is
  1332. that all standard MUI classes use values betwenn 0x80420000 and
  1333. 0x8042ffff for their tags. To avoid conflicts, all you have to do is
  1334. make your tags start with anything but 0x8042.
  1335.  
  1336.    However, if you start distributing your classes to make other people
  1337. benefit from your work and help them in writing better MUI applications,
  1338. things get a bit more complicated. MUI will get confused if two or more
  1339. classes start using some equal tag values. To avoid these problems, I
  1340. suggest to use your MUI serial number together with the TAG_USER bit as
  1341. upper word for your tag items. Thus, if your serial number is e.g. 123,
  1342. all your tag items would look like
  1343.  
  1344.      #define MUIA_Myclass_Foobar     (TAG_USER | (123<<16) | 0x0000)
  1345.      #define MUIA_Myclass_Barfoo     (TAG_USER | (123<<16) | 0x0001)
  1346.      #define MUIA_Myclass_Deadbeaf   (TAG_USER | (123<<16) | 0x0002)
  1347.      #define MUIM_Myclass_Doit       (TAG_USER | (123<<16) | 0x0003)
  1348.      #define MUIM_Myclass_Doit2      (TAG_USER | (123<<16) | 0x0004)
  1349.      
  1350.      #define MUIA_Myotherclass_Attr1 (TAG_USER | (123<<16) | 0x0010)
  1351.      #define MUIA_Myotherclass_Attr2 (TAG_USER | (123<<16) | 0x0011)
  1352.      #define MUIA_Myotherclass_Attr3 (TAG_USER | (123<<16) | 0x0012)
  1353.      #define MUIA_Myotherclass_Attr4 (TAG_USER | (123<<16) | 0x0013)
  1354.  
  1355.    If you aren't registered and don't yet have a serial number, no
  1356. problem... just register *now*! ;-)
  1357.  
  1358. Style Guide
  1359. ***********
  1360.  
  1361. Overview
  1362. ========
  1363.  
  1364.    Note: These topics aren't discussed here just for fun. You will
  1365. annoy lots of users if you don't pay attention to them!
  1366.  
  1367.    - File Requester
  1368.  
  1369.      Even if MUI features a file list and a volume list object and
  1370.      makes building a private file requester very easy, you should
  1371.      always provide a possibility to pop up a standard asl requester
  1372.      for this purpose. Just add a little popup button right beneath
  1373.      your file string gadget and everything will be fine. MUI offers a
  1374.      file-popup object exactly for this purpose.  Note well: Many users
  1375.      (including myself) move programs with non-standard file requesters
  1376.      into the trashcan immediately.
  1377.  
  1378.    - Window Size
  1379.  
  1380.      With MUI, it's very easy to have lots of gadgets within a single
  1381.      window.  Since you as a programmer usually have a more powerful
  1382.      system with higher graphic resolutions as most of your users,
  1383.      windows tend to become too big. You should always make sure that
  1384.      everything you design fits on a standard 640x256 screen with a
  1385.      topaz/8 font. Otherwise, MUI will try to use very small fonts or
  1386.      virtual groups to make your window fit, making your application
  1387.      look and feel bad.
  1388.  
  1389.    - Keyboard Control
  1390.  
  1391.      Even if you're a "mouse-only" user, add keyboard cycle chains and
  1392.      gadget shortcuts to your application. It's very few work for you
  1393.      and helps lots of users.
  1394.  
  1395.    - Background
  1396.  
  1397.      MUI allows the user to adjust lots of different backgrounds for
  1398.      objects.  Even if you don't use this feature, you should always
  1399.      test your program with a fancy background pattern configuration
  1400.      and check whether all your buttons really have button backgrounds,
  1401.      all your framed texts really have text backgrounds, etc.
  1402.  
  1403.    - and last...
  1404.  
  1405.      Don't forget the traditional Amiga style guide!
  1406.  
  1407.